package forumTransform.forumTransformID;

import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;


public class BRun {

    public static void main(String[] args) throws Exception {

    	Path path = FileSystems.getDefault().getPath("C:\\Users\\Dan\\workspace\\forumTransformID\\src\\main\\java\\forumTransform\\forumTransformID", "BBlogs.txt");
    	List<String> blogs = Files.readAllLines(path,java.nio.charset.Charset.defaultCharset());
    	List<BlogspotJSON> allblogs = new ArrayList<BlogspotJSON>();
    	
    	Utils.populateHtmlNumbers();

    	for (Iterator<String> it = blogs.iterator(); it.hasNext();) {
			String url = (String) it.next();
			BlogspotJSON bBlog = Utils.getBInfoDetails(url);
			System.out.println("End of getting info details for "+bBlog.getName() + " with id: "+bBlog.getId());
			try {
				bBlog.populateBlog();
				bBlog.populateComments();
//				allblogs.add(wBlog);
				bBlog.process();
				bBlog.exportPolyCafe();
				ResultFileWriter outWriter		= new ResultFileWriter("participation-"+bBlog.getBlogId(), bBlog.exportCSV(), ".csv");
				outWriter.persist();
				ResultFileWriter outWriter1		= new ResultFileWriter("users-"+bBlog.getBlogId(), bBlog.exportUsersCSV(), ".csv");
				outWriter1.persist();
			} catch (Exception e) {
				// TODO: handle exception
				System.out.println("found an exception ...");
				e.printStackTrace();
				System.out.println("trying to write what we crawled ...");
				try {
					bBlog.exportPolyCafe();
					ResultFileWriter outWriter		= new ResultFileWriter("participation-"+bBlog.getBlogId(), bBlog.exportCSV(), ".csv");
					outWriter.persist();
				} catch (Exception e2) {
					// TODO: handle exception
					System.out.println("found ANOTHER exception ...");
					e.printStackTrace();
					System.out.println("we can not write what we have ... continue");
				}
			}
			//break;
		}
    	System.out.println("End of reading blogs");
    	
    }

}
